<%@ page session="false" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@taglib uri="http://myfaces.apache.org/trinidad" prefix="tr"%>
<%@taglib uri="http://myfaces.apache.org/trinidad/html" prefix="trh"%>

<tr:panelGroupLayout>
<fieldset>
<legend>Wpłaty</legend>

 	<tr:panelHorizontalLayout>
		<tr:commandLink shortDesc="Zapisz wpłatę" 
			rendered="#{not empty paymentBean}" inlineStyle="margin-right:5px"
			action="#{orderController.createPayment}"
			id="createPaymentButton">
				<tr:image source="gfx/save_button24.png" />
		</tr:commandLink>
		<tr:commandLink shortDesc="Anuluj dodawanie" immediate="true"
			rendered="#{not empty paymentBean}"
			actionListener="#{orderController.cancelAddPayment}"
			id="cancelAddPayment" >
				<tr:image source="gfx/delete.png" />
		</tr:commandLink>
		<tr:commandLink shortDesc="Dodaj wpłatę" immediate="true"
			rendered="#{empty paymentBean}"
			actionListener="#{orderController.addEmptyPayment}"
			id="addPaymentButton" >
				<tr:image source="gfx/add_button.png" />
		</tr:commandLink>
	</tr:panelHorizontalLayout>
	
<tr:panelGroupLayout rendered="#{not empty paymentBean}" partialTriggers="addPaymentButton cancelAddPayment createPaymentButton">

			<tr:inputText columns="150" rows="4" label="Treść" id="paymentComment" required="true"
						partialTriggers="addPaymentButton cancelAddPayment createPaymentButton"
						value="#{paymentBean.comment}" shortDesc="Komentarz"/>
			
			<tr:inputText maximumLength="10" id="paymentAmount" value="#{paymentBean.amount}" 
                			  label="Kwota" partialTriggers="addPaymentButton cancelAddPayment createPaymentButton"
                              onkeypress="return checkField(window.self.event, NUMBER_FIELD)"
                              shortDesc="Kwota wpłaty" required="true">
                    <f:convertNumber groupingUsed="false" maxFractionDigits="2" minFractionDigits="2" locale="pl"/>
                    <tr:validateDoubleRange minimum="0.01" />
			</tr:inputText>

</tr:panelGroupLayout>


<tr:panelGroupLayout rendered="#{not empty orderBean.paymentList}" partialTriggers="addPaymentButton cancelAddPayment createPaymentButton">

<div style="height:100px; overflow-x:hidden; overflow-y:auto; width:100%">
	<table cellpadding="3" cellspacing="0" style="width:100%;margin-top:10px; border: 1px solid #ccc">
		<tr style="background-color: #eee;">
			<td>kwota</td>
			<td>treść</td>
			<td align="right">data</td>
			<td width="20">akcja</td>
		</tr>
		<tr:iterator var="payment" rows="0" value="#{orderBean.paymentList}"
						binding="#{orderController.paymentIterator}">
			<tr onMouseOver="this.style.backgroundColor='#e0ffc2'" onMouseOut="this.style.backgroundColor='#FFF'">
				<td style="border-top: 1px solid #ccc;width:5%">
				<tr:outputText value="#{payment.amount}"
                				id="paymentAmount" 
                				shortDesc="Kowta wpłaty">
                    <f:convertNumber groupingUsed="false" maxFractionDigits="2" minFractionDigits="2" locale="pl"/>
                </tr:outputText>
				</td>
				<td style="border-top: 1px solid #ccc">
					<tr:outputFormatted value="#{payment.comment}">
						<f:converter converterId="FormatedTextConverter" />
					</tr:outputFormatted>
				</td>
				<td style="border-top: 1px solid #ccc;width:15%" align="right">
				<tr:outputText value="#{payment.date}">
					<f:convertDateTime pattern="dd-MM-yyyy HH:mm" locale="pl_PL" />
				</tr:outputText>
				</td>

				<td style="border-top: 1px solid #ccc;width:3%">
					<tr:commandLink shortDesc="Usuń"
								actionListener="#{orderController.paymentRemove}"
								rendered="#{currentUserTO.currentSalesman.permissionMap.PAYMENT_REMOVE and
								not SessionDataTO.readOnly}"
								onclick="return confirmMessageBox('Czy chcesz usunąć tą płatność?');">
							<tr:image source="gfx/delete.png" />
					</tr:commandLink>
				</td>
			</tr>
		</tr:iterator>
	</table>
</div>

</fieldset>
</tr:panelGroupLayout>
</tr:panelGroupLayout>